package MyGui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
/**
 * Title:        iPAD
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:      ABB Inc.
 * @author Fangxing Li
 * @version 1.0
 */

public class LogDlg extends MyDlgFrame implements ActionListener{
  private final int GAP = 5;

  private String              sMsg;
  private TitledBorder        border;
  private ElemListScrollPane  scrollPane;

  private JButton btnClear, btnGoto, btnAddToSelection, btnSelect;

  public LogDlg(MainFrame parent, String title) {
      super(parent, title);
      Container pane = this.getContentPane();
      pane.setLayout( new BorderLayout(GAP, GAP));

      //sMsg = "No message.";
      //border = new TitledBorder( sMsg);
      scrollPane = new ElemListScrollPane(mainFrame, ElemListTableModel.PANE_LOG);
      //scrollPane.setBorder( border );
      pane.add( scrollPane, BorderLayout.CENTER );

      JPanel pnlBtns = new JPanel();//new GridLayout(2,2,3,3) );

      btnGoto = new JButton("Goto");
      btnAddToSelection = new JButton("Add to Selection");
      btnSelect = new JButton("Select");
      btnClear = new JButton("Clear");

      pnlBtns.add( btnGoto );
      pnlBtns.add( btnAddToSelection );
      pnlBtns.add( btnSelect );
      pnlBtns.add( btnClear );

      pane.add( pnlBtns, BorderLayout.SOUTH);

      this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
      this.setSize(500, 400);
      //this.setResizable(false);

      btnGoto.addActionListener( this );
      btnAddToSelection.addActionListener( this );
      btnSelect.addActionListener( this );
      btnClear.addActionListener( this );
  }

  public void putData( Vector v){
      scrollPane.getData().addAll(v);
      scrollPane.getModel().fireTableDataChanged();
  }

  public void actionPerformed(ActionEvent evt){
      Object src = evt.getSource();
      if(      src == btnGoto )           { scrollPane.gotoSelectedElem(); }
      else if( src == btnAddToSelection ) { scrollPane.addToSelection(); }
      else if( src == btnSelect )         { scrollPane.select(); }
      else if( src == btnClear )          {
          scrollPane.getData().removeAllElements();
          scrollPane.getModel().fireTableDataChanged();
      }
  }
}